﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlServerCe;
using System.Windows.Forms;
using EMR_System.Controllers;

namespace EMR_System.Forms
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            Session.Instance.User = new User();
            InitializeComponent();
        }

        private void loginBtn_Click(object sender, EventArgs e)
        {
            if (UserController.Login(usernameTB.Text , passwordTB.Text))
            {
                User user = UserController.GetUser(usernameTB.Text);
                Session.Instance.User = new User(user.Username, user.Password);
                Session.Instance.User.FirstName = user.FirstName;
                Session.Instance.User.LastName = user.LastName;
                Session.Instance.User.Type = user.Type;                
                this.Close();
            }
            else
            {
                MessageBox.Show("Username and Password are invalid", "Invalid User Credentials", MessageBoxButtons.OK);
                usernameTB.Focus();
                usernameTB.Text = String.Empty;
                passwordTB.Text = String.Empty;
            }
        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
